#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@author: 
@time: 2024/2/27 9:46 PM
@Function: 请输入模块功能描述
"""
from playwright.sync_api import sync_playwright

playwright=sync_playwright().start()
browser=playwright.chromium.launch(headless = False,slow_mo = 2000)
page=browser.new_page()
page.goto("https://www.baidu.com")
"""
/:从根节点选取
//：从非根节点选取
*：任意节点选取
@：根据属性筛选
text()：根据文本筛选   //em[text()="xxxxx"]
and：关联属性或链接文本
[]：可以防止下标/属性/链接文本
.：选取当前节点
..：选取当前节点的父节点
contains：包含
"""
#单一属性定位
text1=page.locator('//span[@name="tj_settingicon"]').text_content()
print(text1)
text2=page.locator('//span[@name="tj_settingicon" and @id="s-usersetting-top"]').text_content()
print(text2)
text3=page.locator('//div[@id="u1"]/span').text_content()
print(text3)
text4=page.locator('//div[@id="s-top-left"]/a[1]').text_content()
print(text4)
text5=page.locator('//a[@name="tj_fanyi"]/div').text_content()
print(text5)